package com.hyg.lib_music.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hyg.lib_common.DataModel.Music.MusicRecommendCheckData;
import com.hyg.lib_music.R;
import com.makeramen.roundedimageview.RoundedImageView;

import me.drakeet.multitype.ItemViewBinder;

public class MusicRecommendHeadViewBinder extends ItemViewBinder<MusicRecommendCheckData, MusicRecommendHeadViewBinder.ViewHolder>{

    private OnMusicCategoryClickListener onMusicCategoryClickListener;

    @Override
    protected @NonNull
    ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_music_recommend_head, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull MusicRecommendCheckData data) {
        holder.setData(data);
    }


    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        public MusicRecommendCheckData musicCategoryData;
        private @NonNull
        RelativeLayout head;
        private @NonNull
        RoundedImageView headImg;
        private @NonNull
        TextView checkDate;
        private @NonNull
        TextView checkResult;
        private @NonNull
        ImageView img82;


        ViewHolder(@NonNull View itemView) {
            super(itemView);
            head = itemView.findViewById(R.id.head);
            headImg = itemView.findViewById(R.id.headImg);
            checkResult = itemView.findViewById(R.id.checkResult);
            checkDate = itemView.findViewById(R.id.checkDate);
            img82 = itemView.findViewById(R.id.img82);
            head.setOnClickListener(this);
        }

        void setData(@NonNull final MusicRecommendCheckData musicCategoryData) {
            this.musicCategoryData = musicCategoryData;
            headImg.setImageResource(musicCategoryData.checkLogo);
//            Glide.with(MyApp.getInstance()).load(musicCategoryData.checkLogo).error(R.mipmap.headimg).into(headImg);
            checkResult.setText(musicCategoryData.checkResult);
            checkDate.setText(musicCategoryData.checkName+" "+musicCategoryData.checkDate);
            if (musicCategoryData.isExpand == true){
                img82.setImageResource(R.mipmap.down_arrow);
            }else{
                img82.setImageResource(R.mipmap.right_arrow);
            }

        }

        @Override
        public void onClick(View view) {
            if (onMusicCategoryClickListener != null) {
                if (view.getId() == R.id.head) {
                    onMusicCategoryClickListener.onItemClick(view, this.musicCategoryData);
                }
            }
        }
    }

    // 自定义点击事件
    public void setOnMusicCategoryClickListener(OnMusicCategoryClickListener onMusicCategoryClickListener) {
        this.onMusicCategoryClickListener = onMusicCategoryClickListener;
    }

    public interface OnMusicCategoryClickListener {
        void onItemClick(View view, MusicRecommendCheckData musicCategoryData);
    }
}